package com.ss.android.article.base.feature.update.b;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.Pair;

import com.bytedance.article.common.c.TTUtils;
import com.bytedance.common.utility.Logger;
import com.ss.android.article.base.feature.app.a.ArticleConstants;
import com.ss.android.common.AbsApiThread;
import com.ss.android.common.util.NetworkUtils;
import com.ss.android.common.util.UrlBuilder;
import com.ss.android.newmedia.util.AppUtil;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public final class DeleteCommentThread extends AbsApiThread {
    public final class c$a {
        public long a;
        public int b;
        public int c;
        public List d;
        public List e;

        public c$a() {

            this.d = new ArrayList();
            this.e = new ArrayList();
        }
    }

    private final Handler a;
    private final Context b;
    private long c;
    private int d;

    public DeleteCommentThread(Context context, Handler handler, long commentId, int arg6) {
        super("DeleteCommentThread");
        Context v0 = context == null ? null : context.getApplicationContext();
        this.b = v0;
        this.a = handler;
        this.c = commentId;
        this.d = arg6;
    }

    public final void run() {
        JSONObject v0_3;
        String v6;
        int v14 = 10001;
        int v1 = 18;
        long v12 = 0;
        c$a v3 = new c$a();
        v3.a = this.c;
        v3.b = this.d;
        UrlBuilder v0 = new UrlBuilder();
        if (this.d == 5) {
            v0.mUrl = ArticleConstants.dongtaiDeleteUrl;
        } else if (this.d == 6) {
            v0.mUrl = ArticleConstants.dongtaiCommentDeleteUrl;
        } else if (this.d == 4) {
            v0.mUrl = ArticleConstants.dongtaiGroupCommentDelete;
        } else {
            return;
        }

        v0.addParam("id", this.c);
        String v4 = v0.mUrl;
        List v5 = v0.mList;
        int v2 = 0;
        int v0_1 = v1;
        while (true) {
            if (v2 >= 2) {
                break;
            }
            v0_1 = 8192;
            try {
                v6 = NetworkUtils.executePost(v0_1, v4, v5);
                if (v6 != null && v6.length() != 0) {
                    v0_3 = new JSONObject(v6);
                    String v7 = v0_3.getString("message");
                    if (!"success".equals(v7)) {
                        if ("error".equals(v7)) {
                            v0_3 = v0_3.optJSONObject("data");
                            if (v0_3 != null) {
                                v0_3.optString("name");
                            }
                            v0_1 = v1;
                        } else {
                            v0_1 = 17;
                        }
                        Logger.w("snssdk", "update_delete error: " + v6);
                        break;
                    } else {
                        v0_3 = v0_3.optJSONObject("data");
                        if (v0_3 == null) {

                        } else {
                            try {
                                long v6_1 = v0_3.optLong("dongtai_id", 0);
                                if (v6_1 > v12) {
                                    v3.d.add(Long.valueOf(v6_1));
                                }
                                v6_1 = v0_3.optLong("dongtai_comment_id", 0);
                                long v8 = v0_3.optLong("reply_dongtai_id", 0);
                                if (v8 <= v12) {
                                } else if (v6_1 <= v12) {
                                } else {
                                    v3.e.add(new Pair(Long.valueOf(v8), Long.valueOf(v6_1)));
                                }
                            } catch (Exception v0_4) {
                            }
                        }
                        if (this.a == null) {
                            return;
                        }
                        Message v0_5 = this.a.obtainMessage(10001);
                        v0_5.obj = v3;
                        this.a.sendMessage(v0_5);
                        return;
                    }
                }
                v0_1 = v1;
                break;
            } catch (Throwable v0_2) {
                label_79:
                v0_1 = TTUtils.getErrorCode(this.b, v0_2);
                if (!AppUtil.a(v0_1)) {
                    break;
                }
                ++v2;
                continue;
            }
        }


        label_32:
        if (this.a != null) {
            Message v1_1 = this.a.obtainMessage(v14);
            v3.c = v0_1;
            v1_1.obj = v3;
            this.a.sendMessage(v1_1);
        }
    }
}

